// 登录逻辑
document.getElementById('loginForm').addEventListener('submit', function(e) {
    e.preventDefault();
    
    const userName = document.getElementById('userName').value.trim();
    const errorMessage = document.getElementById('errorMessage');
    
    if (!userName) {
        showError('请输入用户名');
        return;
    }
    
    // 存储用户名并跳转到通话页面
    localStorage.setItem('userName', userName);
    window.location.href = '/call';
});

function showError(message) {
    const errorElement = document.getElementById('errorMessage');
    errorElement.textContent = message;
    errorElement.style.display = 'block';
}

// 检查是否已登录
window.addEventListener('DOMContentLoaded', () => {
    const savedUserName = localStorage.getItem('userName');
    if (savedUserName && window.location.pathname === '/') {
        window.location.href = '/call';
    }
});